//==============================================================================
//
//  File        : sensor_HM1375.c
//  Description : Firmware Sensor Control File
//  Author      : Philip Lin
//  Revision    : 1.0
//
//=============================================================================

#include "includes_fw.h"
#if defined(DSC_MP3_P_FW)||defined(VIDEO_AMR_R_FW)||defined(VIDEO_AAC_R_FW)||(SENSOR_EN)
#include "config_fw.h"

#if BIND_SENSOR_HM1375

#include "lib_retina.h"
#include "reg_retina.h"

#include "mmp_reg_vif.h"
#include "mmp_reg_scaler.h"
#include "mmp_reg_gpio.h"
#include "mmp_reg_rawproc.h"

#include "mmpf_sensor.h"
#include "mmpf_hif.h"
#include "mmpf_i2cm.h"
#include "mmpf_vif.h"
#include "isp_if.h"
#include "mmpf_usbpccam.h"

#include "mmp_reg_i2cm.h"
#include "mmps_3gprecd.h"
#include "sensor_HM1375.h"
#include "hdm_ctl.h"
#include "mmpf_dram.h"
#include "motor_ctl.h"
#include "flash_ctl.h"
#include "mmpf_pll.h"

#if (CUSTOMER == ASU)
#define DEFAULT_HM1375_FLIP_FOR_W8_APP	(1)
#else
#define DEFAULT_HM1375_FLIP_FOR_W8_APP	(0)
#endif

static MMPF_I2CM_ATTRIBUTE m_snr_I2cmAttribute = {
            SENSOR_I2CM_ID, SENSOR_I2C_ADDR_HM1375, 16, 8, 0, MMP_FALSE, MMP_FALSE, MMP_FALSE,
            MMP_FALSE, 0, 0, 0, MMPF_I2CM_SPEED_HW_250K, NULL, NULL};


#ifndef SENSOR_ID_HM1375
    #define SENSOR_ID_HM1375 0
#endif


static	MMP_UBYTE   vif_id = 0;

#define G2_CLK                      (120)

extern MMP_USHORT  gsSensorPreviewWidth[], gsSensorPreviewHeight[];
extern MMP_USHORT  gsCurPreviewMode, gsCurPhaseCount;
//extern MMP_USHORT  gsSensorMode;
extern MMP_USHORT  m_usVideoQuality;
extern MMP_USHORT	m_gsISPCoreID;

extern MMPS_3GPRECD_VIDEO_FORMAT m_VideoFmt;
extern MMP_BOOL    gbAutoFocus;

extern MMP_USHORT m_usResolType;
extern MMP_ULONG   glPccamResolution;

#if (IQ_TABLE_LOAD_FROM_FLASH == 0)
//#if ((CUSTOMER == ASU) && (TOTAL_SENSOR_NUMBER == 1)) || (CUSTOMER != ASU)
const __align(4) ISP_UINT8 Sensor_IQ_CompressedText[] = {
        #include "isp_8451_iq_data_v2_HM1375.xls.ciq.txt"
};
//#endif
#endif

#define  SENSOR_ROTATE_180    0

#define  PIXEL_RATE_60M      (1)
#define  PIXEL_RATE_42M      (2)

#define VOLTAGE33V 0
#define VOLTAGE28V 1
#define VOLTAGE18V 2

#define SENSOR_VOLTAGE      VOLTAGE18V
//#if (G1_CLK < 120000)
    #define  SENSOR_PIXEL_RATE          (PIXEL_RATE_42M)
//#else
//    #define  SENSOR_PIXEL_RATE          (PIXEL_RATE_60M)
//#endif

#define BASE_SHUTTER_50HZ		335//346//288//346
#define BASE_SHUTTER_60HZ		279//288//240//288

void SNR_HM1375_SetSensorResolution_Customer(ISP_SENSOR_RESOL res);
void SNR_HM1375_InitSensor_Customer(void);
#if SUPPORT_AUTO_FOCUS
void MOTOR_HM1375_VCM_InitMotor_Customer(void);
void MOTOR_HM1375_VCM_SetAFPosition_Customer(MMP_USHORT af_pos);
#endif

static VENUS_SYSTEM_MODE gSystemMode;

//------------------------------------------------------------------------------
//  Function    : HM1375_Sensor_PreviewMode
//  Description :
//------------------------------------------------------------------------------
extern MMP_BYTE gbSignalType;
extern MMPF_SENSOR_FUNCTION *gsSensorFunction ;

static void HM1375_Sensor_PreviewMode(MMP_USHORT usPreviewmode)
{
	gsCurPreviewMode = usPreviewmode;
	//gsCurPhaseCount = usPhasecount;

	switch (usPreviewmode) {
	case 0:
		RTNA_DBG_Str(3, "Sensor 5M (1920x1080) preview mode\r\n");
		//ISP_IF_3A_Control(ISP_3A_DISABLE); //patrick@100518
	    gsSensorFunction->MMPF_Sensor_Set3AStatus(MMP_FALSE);

		gSystemMode = VENUS_SYSTEM_MODE_SNAPSHOT;//ISP_IF_SNR_SetBeforeCapture();
		ISP_IF_IQ_SetSysMode(1); //Steven NOTE:please reference excel define: 0=capture, 1=preview, 2=video....
		SNR_HM1375_SetSensorResolution_Customer(ISP_SENSOR_RESOL_1280x720);

        //set color transform 16 ~ 235
        MMPF_Scaler_SetOutputColor(MMPF_SCALER_PATH_0, MMP_TRUE, MMPF_SCALER_COLRMTX_BT601); //MMPF_SCALER_COLRMTX_FULLRANGE

		ISP_IF_AE_SetFPS(0);
		//ISP_IF_3A_Control(ISP_3A_ENABLE); //patrick@100518
	    gsSensorFunction->MMPF_Sensor_Set3AStatus(MMP_TRUE);
		break;

	case 1:
		RTNA_DBG_Str(0, "Sensor preview (1280x720) mode\r\n");
		RTNA_DBG_Str(0, "SENSOR_VIDEO_MODE\r\n");
		//ISP_IF_3A_Control(ISP_3A_DISABLE); //patrick@100518
		gsSensorFunction->MMPF_Sensor_Set3AStatus(MMP_FALSE);

		gSystemMode = VENUS_SYSTEM_MODE_PREVIEW;//ISP_IF_SNR_SetBeforePreview();
		ISP_IF_IQ_SetSysMode(1); //Steven NOTE:please reference excel define: 0=capture, 1=preview, 2=video....
		SNR_HM1375_SetSensorResolution_Customer(ISP_SENSOR_RESOL_1280x720);

#if 0
		MMPF_VIF_GetVIFGrabResolution(&ulWidth, &ulHeight);
		dbg_printf(3, "[2] ulWidth = %d, ulHeight = %d\r\n", ulWidth, ulHeight);
#endif

		//set color transform 16 ~ 235
		MMPF_Scaler_SetOutputColor(MMPF_SCALER_PATH_0, MMP_TRUE, MMPF_SCALER_COLRMTX_BT601); //YUV or H264 run BT601 , MPEG run FULLRANGE

		ISP_IF_AE_SetFPS(0);
		//ISP_IF_3A_Control(ISP_3A_ENABLE);
		gsSensorFunction->MMPF_Sensor_Set3AStatus(MMP_TRUE);
		break;
	}
}
extern void GPIO_OutputControl(MMP_UBYTE num, MMP_UBYTE status);
extern volatile MMP_UBYTE   gbDramID;
//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_Initialize
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_Initialize_HM1375(void)
{
	//AITPS_PAD   pPAD  = AITC_BASE_PAD;
	AITPS_VIF   pVIF = AITC_BASE_VIF;

    RES_TYPE_CFG *cur_res;

	RTNA_DBG_Str(0, "MMPF_Sensor_Initialize_HM1375...Begin\r\n");

    //Init globol variable used by DSC
    gsSensorPreviewWidth[0] = 1280;
    gsSensorPreviewHeight[0] = 720;
    // use 1.3M for preview, check sensor preview setting
    gsSensorPreviewWidth[1] = 1280;
    gsSensorPreviewHeight[1] = 720;

    #if 0
	pPAD->PAD_PSCK = PAD_E8_CURRENT | PAD_E4_CURRENT | PAD_PULL_HIGH;
	pPAD->PAD_PSDA = PAD_E4_CURRENT | PAD_PULL_HIGH;
	pPAD->PAD_PSEN = PAD_E4_CURRENT | PAD_PULL_HIGH;
	#endif

//	MMPF_PIO_EnableOutputMode(SEN_RST, MMP_TRUE);
//	MMPF_PIO_EnableOutputMode(SEN_PWR_EN, MMP_TRUE);
//	MMPF_PIO_EnableGpioMode(SEN_RST, MMP_TRUE);
//	MMPF_PIO_EnableGpioMode(SEN_PWR_EN, MMP_TRUE);

//	GPIO_OutputControl(SEN_PWR_EN, MMP_TRUE);





    if((gbDramID == MMPF_DRAMID_WINBOND_SDR16) || (gbDramID == MMPF_DRAMID_WINBOND_SDR16_1_8V)){
        GPIO_OutputControl(GPIO_SENSOR_PSEN, MMP_TRUE);
    	MMPF_OS_Sleep_MS(5);
        GPIO_OutputControl(GPIO_SENSOR_PSEN, MMP_FALSE);
    }
    else{
	    MMPF_VIF_SetPIODir(VIF_SIF_SEN, MMP_TRUE);
	    MMPF_VIF_SetPIOOutput(VIF_SIF_SEN, MMP_TRUE);  //Pin output high
    	MMPF_OS_Sleep_MS(5);
    	MMPF_VIF_SetPIOOutput(VIF_SIF_SEN, MMP_FALSE);//Pin output low
    }

	MMPF_OS_Sleep_MS(5);

    GPIO_OutputControl(SEN_PWR_EN, TRUE);
    MMPF_OS_Sleep_MS(5);
    /*Reset Sensor 500mS*/
//    GPIO_OutputControl(SEN_RST, MMP_FALSE);
//    MMPF_OS_Sleep_MS(5);

    GPIO_OutputControl(SEN_RST, MMP_TRUE);
    MMPF_OS_Sleep_MS(5);


	pVIF->VIF_SENSR_CLK_CTL[vif_id] = VIF_SENSR_CLK_EN;
	MMPF_OS_Sleep_MS(5);

	/*Reset Sensor 500mS*/
	MMPF_VIF_SetPIODir(VIF_SIF_RST, MMP_TRUE);

	MMPF_VIF_SetPIOOutput(VIF_SIF_RST, MMP_FALSE);
	MMPF_OS_Sleep_MS(5);

	MMPF_VIF_SetPIOOutput(VIF_SIF_RST, MMP_TRUE);
	MMPF_OS_Sleep_MS(5);
	#if 1// debug for checking I2C access
	{
	    MMP_USHORT chipid, tmpdata;
        MMPF_OS_Sleep_MS(5);
        gsSensorFunction->MMPF_Sensor_GetReg(0x02, &tmpdata);
        chipid = (tmpdata & 0xFF);
        MMPF_OS_Sleep_MS(5);
        gsSensorFunction->MMPF_Sensor_GetReg(0x01, &tmpdata);
        chipid |= ((tmpdata & 0xFF)<<8);
        if(chipid!=0xFFFF) {
	    RTNA_DBG_Str(0, "Chip ID:");
	    RTNA_DBG_Short(0, chipid);
	    RTNA_DBG_Str(0, "\r\n");
        }else
        {
            RTNA_DBG_Str(0, "Chip ID Read error! Check sensor and I2C\r\n");
        }
	}
	#endif

	SNR_HM1375_InitSensor_Customer();

    cur_res = GetResCfg(glPccamResolution);
    if(cur_res->res_w > gsSensorPreviewWidth[1] || cur_res->res_h > gsSensorPreviewHeight[1]) {
        gsSensorFunction->MMPF_Sensor_SetPreviewMode(0);
        //RTNA_DBG_Str(0, " gsSensorFunction->MMPF_Sensor_SetPreviewMode(0)\n");
    }
    else{
        gsSensorFunction->MMPF_Sensor_SetPreviewMode(1);
        //RTNA_DBG_Str(0, " gsSensorFunction->MMPF_Sensor_SetPreviewMode(1)\n");
    }

#if SUPPORT_AUTO_FOCUS
	MOTOR_HM1375_VCM_InitMotor_Customer();
#endif

#if SUPPORT_FLASH_LIGHT
	VR_Flash_Init();
#endif

	RTNA_DBG_Str(0, "MMPF_Sensor_Initialize_HM1375...End\r\n");
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_PowerDown_HM1375
//  Description :
//------------------------------------------------------------------------------

static MMP_ERR  MMPF_Sensor_PowerDown_HM1375(void)
{
	AITPS_VIF  pVIF = AITC_BASE_VIF;
	//AITPS_MIPI pMIPI = AITC_BASE_MIPI;
	//MMP_UBYTE   vif_id = HM1375_VIFID;

//	gsSensorFunction->MMPF_Sensor_SetReg(0x0100,0);
//	MMPF_OS_Sleep_MS(33);

	MMPF_VIF_EnableInputInterface(MMP_FALSE);

#if SUPPORT_AUTO_FOCUS
 //   VR_Motor_EnterStandby();
    //MMPF_MOTOR_WriteI2C((ISP_IF_AF_GetPos() >> 2) | 0x80, (ISP_IF_AF_GetPos() << 6) & 0xc0);
	//ISP_IF_AF_SetPos(0);
    //ISP_IF_MOTOR_GoToAFPos();
    //gsSensorFunction->MMPF_Sensor_SetAFPosition(0);
	//MMPF_OS_Sleep_MS(10);
#endif

    //MMPF_VIF_SetPIODir(VIF_SIF_RST, MMP_TRUE);
	//MMPF_VIF_SetPIOOutput(VIF_SIF_RST, MMP_TRUE);  //Pin output high
	//MMPF_OS_Sleep_MS(10);
	MMPF_VIF_SetPIOOutput(VIF_SIF_RST, MMP_FALSE);//Pin output low
	MMPF_OS_Sleep_MS(5);
    GPIO_OutputControl(SEN_PWR_EN, MMP_FALSE);
    MMPF_OS_Sleep_MS(5);
    /*Reset Sensor 500mS*/
    GPIO_OutputControl(SEN_RST, MMP_FALSE);
    MMPF_OS_Sleep_MS(5);

    if((gbDramID == MMPF_DRAMID_WINBOND_SDR16) || (gbDramID == MMPF_DRAMID_WINBOND_SDR16_1_8V)){
        GPIO_OutputControl(GPIO_SENSOR_PSEN, MMP_TRUE);
    }
    else{
	    MMPF_VIF_SetPIODir(VIF_SIF_SEN, MMP_TRUE);
	    MMPF_VIF_SetPIOOutput(VIF_SIF_SEN, MMP_TRUE);  //Pin output high
	}
	MMPF_OS_Sleep_MS(5);


	pVIF->VIF_SENSR_CLK_CTL[vif_id] &= (~ VIF_SENSR_CLK_EN) ;   //output sensor main clock


#if 0
	//RTNA_DBG_Str(3, "Config PS_GPIO pin as LOW\r\n");
	pGPIO->GPIO_DATA[3] &= ~(1 << 16);  // Turn Off Sensor Power
#endif
	MMPF_OS_Sleep_MS(20);

	RTNA_DBG_Str3( "MMPF_Sensor_PowerDown_HM1375() \r\n");
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_SetFrameRate_HM1375
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_SetFrameRate_HM1375(MMP_UBYTE ubFrameRate)
{
	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_SetPreviewMode
//  Description :
//------------------------------------------------------------------------------

static MMP_ERR MMPF_Sensor_SetPreviewMode_HM1375(MMP_USHORT usPreviewmode)
{
	HM1375_Sensor_PreviewMode(usPreviewmode);

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_SetPreviewMode
//  Description :
//------------------------------------------------------------------------------

static MMP_ERR MMPF_Sensor_ChangePreviewMode_HM1375(
						MMP_USHORT usCurPreviewmode, MMP_USHORT usCurPhasecount,
						MMP_USHORT usNewPreviewmode, MMP_USHORT usNewPhasecount)
{
	HM1375_Sensor_PreviewMode(usNewPreviewmode);

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_ChangeMode
//  Description :
//------------------------------------------------------------------------------

/*static*/ MMP_ERR MMPF_Sensor_ChangeMode_HM1375(MMP_USHORT usPreviewmode, MMP_USHORT usCapturemode)
{
	switch (usPreviewmode) {
	case 0:
		switch (usCapturemode) {
		case 0:
			break;
		case 1:
			break;
		}
		break;
	case 1:
		switch (usCapturemode) {
		case 0:// SXGA preview, 5M capture
			MMPF_Sensor_SetPreviewMode_HM1375(0);
			// wait 3 frame ...
		   // MMPF_Sensor_WaitFrame(5);
			break;
		case 1:
			MMPF_Sensor_SetPreviewMode_HM1375(1);
			// wait 3 frame ...
			//MMPF_Sensor_WaitFrame(3);

			break;
		}
		break;
	}

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_InitializeVIF
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_InitializeVIF_HM1375(void)
{
	AITPS_MIPI  pMIPI = AITC_BASE_MIPI;
	AITPS_VIF  pVIF = AITC_BASE_VIF;
	//MMP_UBYTE   vif_id = 0;
	ISP_HDM_VIF_IF vif_if;
	MMP_ULONG   ulSENSORCLK;
	MMP_UBYTE div;

	// register sensor (functions and variables)
	//ISP_IF_SNR_Register();
	RTNA_DBG_Str(0, "ISP_IF_SNR_Register...E\r\n");

    #if SUPPORT_AUTO_FOCUS
		MMPF_OS_Sleep_MS(20);
    #endif

#if SUPPORT_AUTO_FOCUS
	// register motor
//	ISP_IF_MOTOR_Register();
#endif

    #if (SENSOR_IF == SENSOR_IF_PARALLEL)
	MMPF_VIF_RegisterInputInterface(MMPF_VIF_PARALLEL);
	pVIF->VIF_SENSR_CTL[vif_id] = VIF_SENSR_LATCH_PST | VIF_LINE_ID_POLAR | VIF_PIXL_ID_POLAR  | VIF_VSYNC_POLAR_NEG ;
    #else
    #if 0
	pMIPI->MIPI_DATA1_SOT = 0x10; // From KW
	pMIPI->MIPI_DATA2_SOT = 0x10; // From KW
	pMIPI->MIPI_DATA3_SOT = 0x10; // From KW
	pMIPI->MIPI_DATA4_SOT = 0x10; // From KW
	#endif

	pMIPI->MIPI_DATA0_DLY[vif_id] = 0x1000;  // set SOT counter to 0x10
	pMIPI->MIPI_DATA1_DLY[vif_id] = 0x1000;  // set SOT counter to 0x10

	MMPF_VIF_RegisterInputInterface(MMPF_VIF_MIPI);
    #endif

	// initialize VIF OPRs
#if (SENSOR_IF == SENSOR_IF_PARALLEL)
	vif_if = ISP_HDM_VIF_IF_PARALLEL;		//ISP_HDM_IF_InitVIF(ISP_HDM_VIF_IF_PARALLEL, 22);
#elif (SENSOR_IF == SENSOR_IF_MIPI_1_LANE)
	vif_if = ISP_HDM_VIF_IF_MIPI_SINGLE_0;	//ISP_HDM_IF_InitVIF(ISP_HDM_VIF_IF_MIPI_SINGLE_0, 22);
#elif (SENSOR_IF == SENSOR_IF_MIPI_2_LANE)
	vif_if = ISP_HDM_VIF_IF_MIPI_DUAL_01;	//ISP_HDM_IF_InitVIF(ISP_HDM_VIF_IF_MIPI_DUAL_01, 22);
#elif (SENSOR_IF == SENSOR_IF_MIPI_4_LANE)
	vif_if = ISP_HDM_VIF_IF_MIPI_QUAD;		//ISP_HDM_IF_InitVIF(ISP_HDM_VIF_IF_MIPI_QUAD, 22);
#endif

	{
		pVIF->VIF_INT_HOST_EN[vif_id] = 0;
		pVIF->VIF_INT_CPU_SR[vif_id] = VIF_INT_ALL;
		pVIF->VIF_OUT_EN[vif_id] = 0;
		//pVIF->VIF_DEFT_EN = 0;
		pVIF->VIF_RAW_OUT_EN[vif_id] = 0;
		pVIF->VIF_FRME_SKIP_NO[vif_id] = 0;
		pVIF->VIF_FRME_SKIP_EN[vif_id] = 0;

		//RTNA_DBG_Str(0,"InitializeVIF\r\n");
		MMPF_PLL_GetGroupFreq(4, &ulSENSORCLK);

#if 1
		if (ulSENSORCLK % 24000) {
            div = VIF_SENSR_CLK_PLL_D12;
		} else {
            div = (ulSENSORCLK / 24000) - 1;//make this to 24MHz
		}
#else
		switch(ulSENSORCLK){
			case 96000:
			    div = VIF_SENSR_CLK_PLL_D4;//24MHz
				break;
			case 144000:
                div = VIF_SENSR_CLK_PLL_D6;//24MHz
				break;
			case 192000:
                div = VIF_SENSR_CLK_PLL_D8;//24MHz
				break;
			case 216000:
                div = VIF_SENSR_CLK_PLL_D9;//24MHz
				break;
			case 240000:
                div = VIF_SENSR_CLK_PLL_D10;//24MHz
				break;
			case 120000:
                div = VIF_SENSR_CLK_PLL_D5;//24MHz
				break;
			default:
                div = VIF_SENSR_CLK_PLL_D12;
				//pVIF->VIF_SENSR_CLK_FREQ[vif_id] = VIF_SENSR_CLK_PLL_D12;  // 144/12 = 12M
				break;
		}
#endif
		pVIF->VIF_SENSR_CLK_FREQ[vif_id] = div;
		dbg_printf(1, "%dKHz div %d\r\n", ulSENSORCLK, div + 1);

		#if (SENSOR_IF==SENSOR_IF_PARALLEL)
		pVIF->VIF_SENSR_CTL[vif_id] = VIF_SENSR_LATCH_PST | VIF_LINE_ID_POLAR | VIF_PIXL_ID_POLAR ;
        #else
		pVIF->VIF_SENSR_CTL[vif_id] = VIF_SENSR_LATCH_PST | VIF_LINE_ID_POLAR | VIF_PIXL_ID_POLAR | VIF_VSYNC_POLAR_NEG;//| VIF_12BPP_OUT_EN;
		//pVIF->VIF_SENSR_CTL[vif_id] = VIF_SENSR_LATCH_PST | VIF_LINE_ID_POLAR | VIF_VSYNC_POLAR_NEG;
        #endif

		pVIF->VIF_YUV_CTL[vif_id] = VIF_YUV_FORMAT_VUY;
/*
        if (vif_id == 0) {
    		pVIF->VIF_0_SENSR_SIF_EN = VIF_SIF_SEN | VIF_SIF_RST;
    		pVIF->VIF_0_SENSR_SIF_DATA = VIF_SIF_RST;
		}
		else {
    		pVIF->VIF_1_SENSR_SIF_EN = VIF_SIF_SEN | VIF_SIF_RST;
    		pVIF->VIF_1_SENSR_SIF_DATA = VIF_SIF_RST;
		}
*/
		pVIF->VIF_SENSR_CLK_CTL[vif_id] = VIF_SENSR_CLK_EN;
		pVIF->VIF_OPR_UPD[vif_id] = VIF_OPR_UPD_EN | VIF_OPR_UPD_FRAME;

		if (vif_if==ISP_HDM_VIF_IF_PARALLEL) {
			RTNA_DBG_Str0("ISP_HDM_VIF_IF_PARALLEL\r\n");
		}
		else {
		    pMIPI->MIPI_DATA0_CFG[vif_id] = ((pMIPI->MIPI_DATA0_CFG[vif_id] & ~MIPI_DAT_SRC_SEL_MASK) | MIPI_DAT_SRC_PHY_1) | MIPI_CSI2_EN;

		    if (vif_if == ISP_HDM_VIF_IF_MIPI_DUAL_01) {
			    pMIPI->MIPI_DATA1_CFG[vif_id] = ((pMIPI->MIPI_DATA1_CFG[vif_id] & ~MIPI_DAT_SRC_SEL_MASK) | MIPI_DAT_SRC_PHY_2) | MIPI_CSI2_EN;
			}
			#if (CHIP == P_V2)
			else if(vif_if==ISP_HDM_VIF_IF_MIPI_QUAD){
			    pMIPI->MIPI_DATA2_CFG = MIPI_CSI2_EN | MIPI_SRC_SEL_2;
			    pMIPI->MIPI_DATA3_CFG = MIPI_CSI2_EN | MIPI_SRC_SEL_3;
			    pMIPI->MIPI_DATA4_CFG = MIPI_CSI2_EN | MIPI_SRC_SEL_4;
			}
			#endif
		}
	}


	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_InitializeISP
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_InitializeISP_HM1375(void)
{
	// register sensor (functions and variables)
	RTNA_DBG_Str(0, "ISP_IF_LIB_Init...\r\n");
	// check if ISP Lib and IQ are mismatched.
	ISP_IF_LIB_Init();
	// check if ISP Lib and IQ are mismatched.
	if (ISP_IF_LIB_CompareIQVer() != MMP_ERR_NONE) {
		RTNA_DBG_Str(0, "Wrong ISP lib version!\r\n");
	    return MMP_ERR_NONE;
	}

	//RTNA_DBG_Str(0, "ISP_IF_3A_Init...S\r\n");
	// initialize 3A
	ISP_IF_3A_Init();

	// set AF type (ISP_AF_TYPE_ONE_SHOT / ISP_AF_TYPE_CONTINUOUS)
	ISP_IF_AF_SetType(ISP_AF_TYPE_CONTINUOUS);
	//RTNA_DBG_Str(0, "ISP_IF_3A_Init...E\r\n");

	ISP_IF_AE_SetLowLuxMode(0);//disable Low light Compensation

	return  MMP_ERR_NONE;
}

//============================================================================

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_SetAFPosition_HM1375
//  Description :
// ---------------------------------------
static MMP_ERR MMPF_Sensor_SetAFPosition_HM1375(MMP_UBYTE ubPos)
{
#if SUPPORT_AUTO_FOCUS
	//if (gISPConfig.AutoFocusMode == VENUS_AF_MODE_MANUAL) {
		//gAFConfig.AFPos = ubPos;
		ISP_IF_AF_SetPos(ubPos, 8);
		MOTOR_HM1375_VCM_SetAFPosition_Customer(ISP_IF_AF_GetPos(0));
	//}

            //RTNA_DBG_Str(3, "  ubPos = ");
            //RTNA_DBG_Short(3, ubPos);
            //RTNA_DBG_Str(3, "\r\n");
#endif
	return  MMP_ERR_NONE;
}
static ISP_UINT32 gISPFrameCnt = 0;
static ISP_UINT32 frame_div = 3;
//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_Do3AOperation
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAWBOperation_HM1375(void)
{

//	ISP_IF_R_DoAWB();
	switch (gISPFrameCnt % frame_div) {
	case 1:
		ISP_IF_AWB_Execute();
		ISP_IF_IQ_SetAWBGains(ISP_IF_AWB_GetGainR(), ISP_IF_AWB_GetGainG(), ISP_IF_AWB_GetGainB());
	break;
	case 2:
		ISP_IF_CALI_Execute();
	break;

	}
	return  MMP_ERR_NONE;
}

//ISP_UINT32 gISPFrameCnt;
ISP_UINT32 s_gain_HM1375; //For Color patch infor
//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoAEOperation_ST
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAEOperation_ST_HM1375(void)
{
    static ISP_UINT32 frame_cnt = 0;
	static ISP_UINT32 again, dgain, s_gain;
    if(ISP_IF_3A_GetSwitch(ISP_3A_ALGO_AE) != 1) return MMP_ERR_NONE;

    switch (frame_cnt++ % 6) {
//  switch (gISPFrameCnt++ % 6) {
    case 0:
        ISP_IF_AE_Execute();

        again = ISP_IF_AE_GetAGain();
        dgain = ISP_IF_AE_GetDGain();
        s_gain = VR_MIN(16 * VR_MAX(again, ISP_IF_AE_GetAGainBase()) / ISP_IF_AE_GetAGainBase() , 127);

        // special conversion for exposure parameters could be set here ===========================
        if (again > 0x100) {
            dgain = ((ISP_UINT32)dgain * (ISP_UINT32)(again>>2)) / VR_MAX(((again & 0x3F0)>>2),1);
            again = again & 0x3F0;
        } else if (again > 0x80) {
            dgain = ((ISP_UINT32)dgain * (ISP_UINT32)(again>>2)) / VR_MAX(((again & 0x3F8)>>2),1);
            again = again & 0x3F8;
        } else {
            dgain = ((ISP_UINT32)dgain * (ISP_UINT32)again) / VR_MAX((again & 0x3FC),1);
            again = again & 0x3FC;
        }

        if (s_gain > 0x20 && s_gain < 0x40) {
           dgain = dgain * s_gain / (s_gain & 0xFE);
           again = again * (s_gain & 0xFE) /s_gain;
        }

        if (s_gain > 0x40 && s_gain < 0x80) {
           dgain = dgain * s_gain / (s_gain & 0xFC);
           again = again * (s_gain & 0xFC) /s_gain;
        }
        // end of special conversion ==============================================================

        gsSensorFunction->MMPF_Sensor_SetSensorShutter(ISP_IF_AE_GetShutter(), ISP_IF_AE_GetVsync());
        break;

    case 2:
        //ISP_IF_SNR_SetShutter(ISP_IF_AE_GetShutter(), ISP_IF_AE_GetVsync());
        ISP_IF_IQ_SetAEGain(again);
        break;
    }

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoAEOperation_END
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAEOperation_END_HM1375(void)
{
    static ISP_UINT32 frame_cnt = 0;
    static ISP_UINT32 again, dgain, s_gain;

    if(ISP_IF_3A_GetSwitch(ISP_3A_ALGO_AE) != 1) return MMP_ERR_NONE;

    ISP_IF_AE_GetHWAcc(1);

    switch (frame_cnt++ % 6) {
//  switch (gISPFrameCnt++ % 6) {
    case 2:
        again = ISP_IF_AE_GetAGain();
        dgain = ISP_IF_AE_GetDGain();
        s_gain = VR_MIN(16 * VR_MAX(again, ISP_IF_AE_GetAGainBase()) / ISP_IF_AE_GetAGainBase() , 127);

        // special conversion for exposure parameters could be set here ===========================
        if (again > 0x100) {
            dgain = ((ISP_UINT32)dgain * (ISP_UINT32)(again>>2)) / VR_MAX(((again & 0x3F0)>>2),1);
            again = again & 0x3F0;
        } else if (again > 0x80) {
            dgain = ((ISP_UINT32)dgain * (ISP_UINT32)(again>>2)) / VR_MAX(((again & 0x3F8)>>2),1);
            again = again & 0x3F8;
        } else {
            dgain = ((ISP_UINT32)dgain * (ISP_UINT32)again) / VR_MAX((again & 0x3FC),1);
            again = again & 0x3FC;
        }

        if (s_gain > 0x20 && s_gain < 0x40) {
           dgain = dgain * s_gain / (s_gain & 0xFE);
           again = again * (s_gain & 0xFE) /s_gain;
        }

        if (s_gain > 0x40 && s_gain < 0x80) {
           dgain = dgain * s_gain / (s_gain & 0xFC);
           again = again * (s_gain & 0xFC) /s_gain;
        }
        // end of special conversion ==============================================================

        ISP_IF_IQ_SetAEGain(dgain);
        //ISP_IF_SNR_SetAddMode(ISP_IF_AE_GetAdditionMode());
        break;
    }
// ISP_IF_AWB_GetHWAcc(1);
// ISP_IF_AE_GetHWAcc(1);
//{
//    if(ISP_IF_3A_GetSwitch(ISP_3A_ALGO_AE) != 1) return MMP_ERR_NONE;
//
//	switch (gISPFrameCnt++ % frame_div) {
//	case 1:
//		ISP_IF_IQ_SetAEGain(ISP_IF_AE_GetDGainBase());
//		break;
//	case 2:
////		ISP_IF_AE_GetHWAcc(1);
//#if (MotionDetection == 1)
//		COLOR_StoreAEAcc();
//#endif
//		break;
//	}
//}
	return  MMP_ERR_NONE;
}


//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoAFOperation
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAFOperation_HM1375(void)
{
#if SUPPORT_AUTO_FOCUS
	if(gbAutoFocus == MMP_TRUE){
		//VR_AF_GetAcc();
		ISP_IF_AF_GetHWAcc(1);
		//ISP_IF_R_DoAF();
	}
#endif

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoAFOperation
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_Sensor_DoAFOperation_FrameStart_HM1375(void)
{
#if SUPPORT_AUTO_FOCUS
	if(gbAutoFocus == MMP_TRUE){
		//VR_AF_GetAcc();
		//ISP_IF_R_GetAFAcc();
		//ISP_IF_R_DoAF();
		{
			static ISP_UINT32 frame_cnt = 0;

			switch (frame_cnt++ % 1) {
			case 0:
				ISP_IF_AF_Execute();
				MOTOR_HM1375_VCM_SetAFPosition_Customer(ISP_IF_AF_GetPos(0));
				break;
			}
		}
	}
#endif

	return  MMP_ERR_NONE;
}

//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_DoIQOperation_HM1375
//  Description :
//------------------------------------------------------------------------------
//extern MMP_UBYTE gbSkypeMode;
extern H264_FORMAT_TYPE gbCurH264Type;
static MMP_ERR  MMPF_Sensor_DoIQOperation_HM1375(void)
{
	// switch IQ table if video format is H264
	//PCAM_USB_VIDEO_FORMAT vidFmt = pcam_get_info()->pCamVideoFormat;

	//if (vidFmt == PCAM_USB_VIDEO_FORMAT_H264)	ISP_IF_F_SetVideoMode(1);
	//else										ISP_IF_F_SetVideoMode(0);


	// set IQ at frame end to ensure frame sync
	ISP_IF_IQ_SetAll();
#if SUPPORT_ISP_ENGINEERING_MODE_FUNCTION
	{
	extern MMP_USHORT PCAM_UpdateGAMMAtoRAM(void);
	PCAM_UpdateGAMMAtoRAM();
	}
#endif
	ISP_IF_IQ_CheckBypass();

	//RTNA_DBG_Str(0, "DoIQOperation_HM1375()\r\n");

	return  MMP_ERR_NONE;
}

// Steven ADD
//------------------------------------------------------------------------------
//  Function    : MMPF_SetLightFreq
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR  MMPF_SetLightFreq_HM1375(MMP_USHORT usMode)
{
#if 0

	RTNA_DBG_Str(0, "MMPF_SetLightFreq_HM1375 : ");
	RTNA_DBG_Short(0, usMode);
	RTNA_DBG_Str(0, "\r\n");

	/*
	typedef enum {
		VENUS_FLICKER_MODE_OFF              = 0,
		VENUS_FLICKER_MODE_AUTO             = 1,
		VENUS_FLICKER_MODE_60HZ             = 2,
		VENUS_FLICKER_MODE_50HZ             = 3,
		VENUS_FLICKER_MODE_CAL_BASESHUTTER  = 4
	} VENUS_FLICKER_MODE;
	*/

	switch(usMode) {
	case 0:
	case 2:
		//gISPConfig.FlickerMode = VENUS_FLICKER_MODE_60HZ;
		ISP_IF_AE_SetFlicker(ISP_AE_FLICKER_60HZ);
		break;
	case 1:
	case 3:
		//gISPConfig.FlickerMode = VENUS_FLICKER_MODE_50HZ;
		ISP_IF_AE_SetFlicker(ISP_AE_FLICKER_50HZ);
		break;
	default:
		//gISPConfig.FlickerMode = VENUS_FLICKER_MODE_AUTO;
		ISP_IF_AE_SetFlicker(ISP_AE_FLICKER_AUTO);
	}
#endif

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_SetStableState_HM1375(MMP_BOOL bStableState)
{
	return  MMP_ERR_NONE;
}

MMP_ERR MMPF_SetHistEQState_HM1375(MMP_BOOL bHistEQState)
{

	return  MMP_ERR_NONE;
}

extern volatile MMP_UBYTE gbDramID;
static MMP_ERR  MMPF_Sensor_SetReg_HM1375(MMP_USHORT usAddr, MMP_USHORT usData)
{
	if((gbDramID == MMPF_DRAMID_WINBOND_SDR16) || (gbDramID == MMPF_DRAMID_WINBOND_SDR16_1_8V)){
        m_snr_I2cmAttribute.uI2cmID = MMPF_I2CM_ID_0;  // for AIT8433 70 pin package
    }
    else{
        m_snr_I2cmAttribute.uI2cmID = MMPF_I2CM_ID_1;  // for AIT8451 105 pin package
    }
	MMPF_I2cm_WriteReg(&m_snr_I2cmAttribute, usAddr, usData);
	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_GetReg_HM1375(MMP_USHORT usAddr, MMP_USHORT *usData)
{
	*usData = 0xFF;
	if((gbDramID == MMPF_DRAMID_WINBOND_SDR16) || (gbDramID == MMPF_DRAMID_WINBOND_SDR16_1_8V)){
        m_snr_I2cmAttribute.uI2cmID = MMPF_I2CM_ID_0;  // for AIT8433 70 pin package
    }
    else{
        m_snr_I2cmAttribute.uI2cmID = MMPF_I2CM_ID_1;  // for AIT8451 105 pin package
    }
    MMPF_I2cm_ReadReg(&m_snr_I2cmAttribute, usAddr, usData);

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetImageScene_HM1375(MMP_USHORT imgSceneID)
{
#if 0
/*
typedef enum {
	ISP_SCENE_AUTO					= 0,	// scene mode
	ISP_SCENE_PORTRAIT				= 1,	// scene mode
	ISP_SCENE_LANDSCAPE				= 2,	// scene mode
	ISP_SCENE_SPORTS				= 3,	// scene mode
	ISP_SCENE_SUNSET				= 4,	// scene mode
	ISP_SCENE_DUSK					= 5,	// scene mode
	ISP_SCENE_DAWN					= 6,	// scene mode
	ISP_SCENE_NIGHT_SHOT			= 7,	// scene mode
	ISP_SCENE_AGAINST_LIGHT			= 8,	// scene mode
	ISP_SCENE_TEXT					= 9,	// scene mode
	ISP_SCENE_MANUAL				= 10,	// scene mode
	ISP_SCENE_INDOOR				= 11,	// scene mode
	ISP_SCENE_SNOW					= 12,	// scene mode
	ISP_SCENE_FALL					= 13,	// scene mode
	ISP_SCENE_WAVE					= 14,	// scene mode
	ISP_SCENE_FIREWORKS				= 15,	// scene mode
	ISP_SCENE_SHOW_WIN				= 16,	// scene mode
	ISP_SCENE_CANDLE				= 17,	// scene mode
	ISP_SCENE_NONE					= 18	// camera mode
} ISP_SCENE;
*/
	imgSceneID = (imgSceneID % (ISP_SCENE_NONE+1));

	RTNA_DBG_Str(3, "MMPF_SetImageScene_HM1375 : ");
	RTNA_DBG_Byte(3, imgSceneID);
	RTNA_DBG_Str(3, "\r\n");

	//if (g3AConfig.Control3A == ISP_3A_ENABLE)
		MMPF_Sensor_CheckFrameEnd(1);
	ISP_IF_F_SetScene(imgSceneID);
#endif

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetAEMode_HM1375(MMP_UBYTE ubAEMode, MMP_UBYTE ubISOMode)
{
#if 0
/*
typedef enum {
	AE_MODE_AUTO						= 0,
	AE_MODE_MANUAL						= 1,
	AE_MODE_ISO							= 2,
	AE_MODE_SHUTTER						= 3
} VENUS_AE_MODE;
*/
/*
typedef enum {
	AE_ISO_AUTO					= 0,
	AE_ISO_50					= 1,
	AE_ISO_100					= 2,
	AE_ISO_200					= 3,
	AE_ISO_400					= 4,
	AE_ISO_800					= 5,
	AE_ISO_1600					= 6,
	AE_ISO_3200					= 7,
	ISP_AE_ISO_NUM
} VENUS_AE_ISO;
*/
    #if 0 //FIXME, VSN_V2
	if (ubAEMode == 3)
		ISP_IF_AE_SetISO(ISP_AE_MODE_AUTO);
	else
	#endif
		ISP_IF_AE_SetISO(ubISOMode);
#endif

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetAFMode_HM1375(MMP_UBYTE ubAFMode)
{
#if 0
/*
typedef enum {
	VENUS_AF_MODE_AUTO					= 0,
	VENUS_AF_MODE_MANUAL				= 1,
	VENUS_AF_MODE_MACRO					= 2,
	VENUS_AF_MODE_FULL					= 3,
	VENUS_AF_MODE_MOTOR_TEST            = 4,
	VENUS_AF_MODE_NULL					= 5
} VENUS_AF_MODE;
*/
	RTNA_DBG_Str(3, "MMPF_Sensor_SetAFMode_HM1375 : ");
	RTNA_DBG_Byte(3, ubAFMode);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.AutoFocusMode = (MMP_UBYTE)ubAFMode;
	//if (g3AConfig.Control3A == ISP_3A_ENABLE)
	//	MMPF_Sensor_CheckFrameEnd(1);
	ISP_IF_AF_SetMode(ubAFMode);
#endif

	return  MMP_ERR_NONE;
}

//======================================================================//
// function : MMPF_Sensor_SetImageEffect                                //
// parameters:                                                          //
// return :                                                             //
// description :                                                        //
//======================================================================//
static MMP_ERR  MMPF_Sensor_SetImageEffect_HM1375(MMP_USHORT imgEffectID)
{
#if 0
/*
typedef enum {
	ISP_IMAGE_EFFECT_NORMAL			= 0,
	ISP_IMAGE_EFFECT_GREY			= 1,
	ISP_IMAGE_EFFECT_SEPIA			= 2,
	ISP_IMAGE_EFFECT_NEGATIVE		= 3,
	ISP_IMAGE_EFFECT_ANTIQUE		= 4,
	ISP_IMAGE_EFFECT_WATERCOLOR		= 5,
	ISP_IMAGE_EFFECT_PORTRAIT		= 6,
	ISP_IMAGE_EFFECT_LANDSCAPE		= 7,
	ISP_IMAGE_EFFECT_SUNSET			= 8,
	ISP_IMAGE_EFFECT_DUSK			= 9,
	ISP_IMAGE_EFFECT_DAWN			= 10,
	ISP_IMAGE_EFFECT_RED			= 11,
	ISP_IMAGE_EFFECT_GREEN			= 12,
	ISP_IMAGE_EFFECT_BLUE			= 13,
	ISP_IMAGE_EFFECT_YELLOW			= 15,
	ISP_IMAGE_EFFECT_EMBOSS			= 17,
	ISP_IMAGE_EFFECT_OIL			= 18,
	ISP_IMAGE_EFFECT_BW				= 19,
	ISP_IMAGE_EFFECT_SKETCH			= 20,
	ISP_IMAGE_EFFECT_CRAYONE		= 21,
	ISP_IMAGE_EFFECT_WHITEBOARD		= 22,
	ISP_IMAGE_EFFECT_BLACKBOARD		= 23,
	ISP_IMAGE_EFFECT_VIVID			= 24,
	ISP_IMAGE_EFFECT_NUM
} ISP_IMAGE_EFFECT;
*/

	imgEffectID = (imgEffectID % (ISP_IMAGE_EFFECT_NUM+1));

	RTNA_DBG_Str(3, "MMPF_Sensor_SetImageEffect_HM1375 : ");
	RTNA_DBG_Byte(3, imgEffectID);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.ImageEffect = (MMP_USHORT)imgEffectID;
	//if (g3AConfig.Control3A == ISP_3A_ENABLE)
	//	MMPF_Sensor_CheckFrameEnd(1);
	ISP_IF_F_SetImageEffect(imgEffectID);
#endif

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetAWBType_HM1375(MMP_UBYTE ubType)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_SetAWBType_HM1375 : ");
	RTNA_DBG_Byte(3, ubType);
	RTNA_DBG_Str(3, "\r\n");

	cAWBtype = ubType;
#endif
	return  MMP_ERR_NONE;
}
static MMP_ERR  MMPF_Sensor_SetContrast_HM1375(MMP_SHORT ubLevel)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_Contrast_HM1375 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.ContrastLevel = ubLevel;
	ISP_IF_F_SetContrast(ubLevel);
#endif

	return  MMP_ERR_NONE;
}
static MMP_ERR  MMPF_Sensor_SetSaturation_HM1375(MMP_SHORT ubLevel)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_SetSaturation_HM1375 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.SaturationLevel = ubLevel;
	ISP_IF_F_SetSaturation(ubLevel);
#endif

	return  MMP_ERR_NONE;
}
static MMP_ERR  MMPF_Sensor_SetSharpness_HM1375(MMP_SHORT ubLevel)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_SetSharpness_HM1375 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	//gISPConfig.SharpnessLevel = ubLevel;
	ISP_IF_F_SetSharpness(ubLevel);
#endif

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetHue_HM1375(MMP_SHORT ubLevel)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_SetHue_HM1375 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	ISP_IF_F_SetHue(ubLevel);
#endif

	return  MMP_ERR_NONE;
}

static MMP_ERR  MMPF_Sensor_SetGamma_HM1375(MMP_SHORT ubLevel)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_SetGamma_HM1375 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

	ISP_IF_F_SetGamma(ubLevel);
#endif

	return  MMP_ERR_NONE;
}

/*static MMP_ERR  MMPF_Sensor_SetBacklight_HM1375(MMP_UBYTE ubLevel)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_SetBacklight_HM1375 : ");
	RTNA_DBG_Byte(3, ubLevel);
	RTNA_DBG_Str(3, "\r\n");

//	ISP_IF_F_SetBacklight(ubLevel);
	if(ubLevel > 1){
		ISP_IF_F_SetWDR(ISP_WDR_DISABLE);
	}
	else{
		ISP_IF_F_SetWDR(ISP_WDR_ENABLE);
	}
#endif

	return  MMP_ERR_NONE;
}

*/

static void  MMPF_Sensor_SetCaptureISPSetting_HM1375(MMP_UBYTE usCaptureBegin)
{
#if 0
	AITPS_VIF   pVIF = AITC_BASE_VIF;
	MMP_ULONG   ulVIF_Width, ulVIF_Height;
	//MMP_UBYTE   vif_id = 0;

	/* ToDo: setting IOS and ISP windows*/
	if(MMP_TRUE == usCaptureBegin){
		ulVIF_Width = (pVIF->VIF_GRAB[vif_id].PIXL_ED - pVIF->VIF_GRAB[vif_id].PIXL_ST + 1);
		ulVIF_Height = (pVIF->VIF_GRAB[vif_id].LINE_ED - pVIF->VIF_GRAB[vif_id].LINE_ST + 1);
		//gSensorFunc.SetISPWindows(ulVIF_Width,ulVIF_Height);
	}
#endif

	return;
}

/*Prepare for raw preview zoom*/
static void  MMPF_Sensor_SetISPWindow_HM1375(MMP_ULONG ulWidth, MMP_ULONG ulHeight)
{
	//gSensorFunc.SetISPWindows(ulWidth,ulHeight);
	return;
}

/*Check AIT can preview in this resolution*/
static MMP_UBYTE  MMPF_Sensor_CheckPreviewAbility_HM1375(MMP_USHORT usPreviewmode)
{
#if 0
	switch(usPreviewmode){
		case 0:                 //5M can't preview
			return MMP_TRUE;
			break;
		case 1:                 //1.3M can preview
			return MMP_TRUE;
			break;
	}
#endif

	return MMP_TRUE;            //5M and 1.3M always can preview
}

static void SetAFWin_HM1375(MMP_USHORT usIndex, MMP_USHORT usPreviewWidth, MMP_USHORT usPreviewHeight,
					MMP_USHORT  usStartX, MMP_USHORT  usStartY, MMP_USHORT  usWidth, MMP_USHORT  usHeight)
{

	//DBG_S3("SetAFWin (TODO)\r\n");
}

//static MMP_BOOL VGAPreview = MMP_TRUE;
static void SetAFEnable_HM1375(MMP_UBYTE enable)
{
//    if (enable) {
		//RTNA_DBG_Str(3, "VENUS_ISP_AUTO_FOCUS_STATUS_START\r\n");
		ISP_IF_AF_Control(ISP_AF_START);
		//actually calling SNR_HM1375_SetAutoFocusControl()
//    } else {
//        RTNA_DBG_Str(3, "VENUS_ISP_AUTO_FOCUS_STATUS_STOP\r\n");
//        ISP_IF_AF_Control(ISP_AF_STOP);
//    }
}

static MMP_ERR MMPF_Sensor_SetAEEnable_HM1375(MMP_UBYTE bEnable)
{
	/*
	if (bEnable) {
		g3AConfig.AE_Enabled     = ON;
	}
	else {
		g3AConfig.AE_Enabled     = OFF;
	}*/

	ISP_IF_3A_SetSwitch(ISP_3A_ALGO_AE, bEnable);

	return MMP_ERR_NONE;
}

static MMP_ERR MMPF_Sensor_SetAWBEnable_HM1375(MMP_UBYTE bEnable)
{
#if 0
	if (bEnable) {
		g3AConfig.AWB_Enabled    = ON;
		g3AConfig.AWBRGB_Enabled = ON;
	}
	else {
		g3AConfig.AWB_Enabled    = OFF;
		g3AConfig.AWBRGB_Enabled = OFF;
	}
#endif

	if(bEnable)
		ISP_IF_AWB_SetMode(ISP_AWB_MODE_AUTO);
	else
		ISP_IF_AWB_SetMode(ISP_AWB_MODE_MANUAL);

	return MMP_ERR_NONE;
}
static void SetAEsmooth_HM1375(MMP_UBYTE smooth)  {return;}
static MMP_ERR MMPF_Sensor_SetExposureValue_HM1375(MMP_UBYTE ev)
{
#if 0
	RTNA_DBG_Str(3, "MMPF_Sensor_SetExposureValue_HM1375 : ");
	//RTNA_DBG_Byte(3, gISPConfig.EV);
	//RTNA_DBG_Str(3, " : ");
	RTNA_DBG_Byte(3, ev);
	RTNA_DBG_Str(3, "\r\n");

	ISP_IF_AE_SetEV(ev);
#endif

	return MMP_ERR_NONE;
}

static MMP_UBYTE GetAFPosition_HM1375     (void){ return 0;/*volatile MMP_UBYTE *GPIO_BASE_B = (volatile MMP_UBYTE *)0x80009400;  return GPIO_BASE_B[0xB0];*/}


static MMP_UBYTE GetAFEnable_HM1375(void)
{
	//return 0;
	return ISP_IF_AF_GetResult();
}

static MMP_UBYTE GetExposureValue_HM1375  (void){return ISP_IF_AE_GetEV();}
static MMP_UBYTE GetAEsmooth_HM1375       (void){return 0;}
//------------------------------------------------------------------------------
//  Function    : MMPF_Sensor_Set3AStatus
//  Description :
//------------------------------------------------------------------------------
static MMP_ERR	MMPF_Sensor_Set3AStatus_HM1375(MMP_BOOL bEnable)
{
	#if 1
	MMPF_Sensor_3A_SetInterrupt(bEnable);
	//#else
	if (bEnable)
		ISP_IF_3A_Control(ISP_3A_ENABLE);
	else
		ISP_IF_3A_Control(ISP_3A_DISABLE);
	#endif
	return	MMP_ERR_NONE;
}

static void  MMPF_Sensor_SetColorID_HM1375(MMPF_SENSOR_ROTATE_TYPE RotateType)
{
	switch(RotateType) {
#if DEFAULT_HM1375_FLIP_FOR_W8_APP
	case MMPF_SENSOR_ROTATE_NO_ROTATE:
		gsSensorFunction->MMPF_Sensor_SetReg(0x101, 0x02);
		ISP_IF_IQ_SetColorID(2);
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_90:
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_180:
		gsSensorFunction->MMPF_Sensor_SetReg(0x101, 0x01);
		ISP_IF_IQ_SetColorID(3);
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_270:
		break;
	case MMPF_SENSOR_ROTATE_H_MIRROR:
		gsSensorFunction->MMPF_Sensor_SetReg(0x101, 0x03);
		ISP_IF_IQ_SetColorID(3);
		break;
	case MMPF_SENSOR_ROTATE_V_FLIP:
		gsSensorFunction->MMPF_Sensor_SetReg(0x101, 0x00);
		ISP_IF_IQ_SetColorID(2);
		break;
#else

	case MMPF_SENSOR_ROTATE_NO_ROTATE:
		gsSensorFunction->MMPF_Sensor_SetReg(0x0006, 0x00);
		ISP_IF_IQ_SetColorID(0);
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_90:
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_180:
		gsSensorFunction->MMPF_Sensor_SetReg(0x0006, 0x03);
		ISP_IF_IQ_SetColorID(0);
		break;
	case MMPF_SENSOR_ROTATE_RIGHT_270:
		break;
	case MMPF_SENSOR_ROTATE_H_MIRROR:
		gsSensorFunction->MMPF_Sensor_SetReg(0x0006, 0x02);
		ISP_IF_IQ_SetColorID(0);
		break;
	case MMPF_SENSOR_ROTATE_V_FLIP:
		gsSensorFunction->MMPF_Sensor_SetReg(0x0006, 0x01);
		ISP_IF_IQ_SetColorID(0);
		break;
#endif
	}

	ISP_IF_IQ_SetDirection((ISP_UINT8)RotateType);
	return;
}

const ISP_UINT8 get_HM1375_gain_Customer[128] =
{
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,
    0x00,

    0x00, //0x10
    0x01,
    0x02,
    0x03,
    0x04,
    0x05,
    0x06,
    0x07,
    0x08,
    0x09,
    0x0a,
    0x0b,
    0x0c,
    0x0d,
    0x0e,
    0x0f,


    0x11,//0x20
    0x11,
    0x12,
    0x12,
    0x13,
    0x13,
    0x14,
    0x14,
    0x15,
    0x15,
    0x16,
    0x16,
    0x17,
    0x17,
    0x18,
    0x18,


    0x19,//0x30
    0x19,
    0x1a,
    0x1a,
    0x1b,
    0x1b,
    0x1c,
    0x1c,
    0x1d,
    0x1d,
    0x1e,
    0x1e,
    0x1f,
    0x1f,
    0x31,
    0x31,

    0x31,//0x40
    0x31,
    0x31,
    0x31,
    0x32,
    0x32,
    0x32,
    0x32,
    0x33,
    0x33,
    0x33,
    0x33,
    0x34,
    0x34,
    0x34,
    0x34,

    0x35,//0x50
    0x35,
    0x35,
    0x35,
    0x36,
    0x36,
    0x36,
    0x36,
    0x37,
    0x37,
    0x37,
    0x37,
    0x38,
    0x38,
    0x38,
    0x38,

    0x39,//0x60
    0x39,
    0x39,
    0x39,
    0x3a,
    0x3a,
    0x3a,
    0x3a,
    0x3b,
    0x3b,
    0x3b,
    0x3b,
    0x3c,
    0x3c,
    0x3c,
    0x3c,

    0x3d,//0x70
    0x3d,
    0x3d,
    0x3d,
    0x3e,
    0x3e,
    0x3e,
    0x3e,
    0x3f,
    0x3f,
    0x3f,
    0x3f,
    0x71,
    0x71,
    0x71,
    0x71,
};

static void MMPF_Sensor_SetSensorGain_HM1375(MMP_ULONG gain)
{
    MMP_USHORT s_gain;
    MMP_ULONG sensor_gain;
//    return;
    s_gain = VR_MIN(16 * VR_MAX(gain, ISP_IF_AE_GetAGainBase()) / ISP_IF_AE_GetAGainBase() , 127);
    sensor_gain = get_HM1375_gain_Customer[s_gain] ;
    gsSensorFunction->MMPF_Sensor_SetReg(0x38, (sensor_gain >> 8) & 0x01);
    gsSensorFunction->MMPF_Sensor_SetReg(0x3D, sensor_gain & 0xff);
    return;
}

static void MMPF_Sensor_SetSensorShutter_HM1375(MMP_ULONG shutter, MMP_ULONG vsync)
{
	MMP_ULONG new_vsync =  VR_MAX(vsync, shutter + 5);  //+8
	MMP_ULONG new_shutter = VR_MIN(VR_MAX(shutter, 1), new_vsync - 2);
	MMP_ULONG ExtraVsyncWidth;

	return;//T.B.D

	gsSensorFunction->MMPF_Sensor_SetReg(0x380E, new_vsync >> 8);
	gsSensorFunction->MMPF_Sensor_SetReg(0x380F, new_vsync);

    if(new_shutter <= (new_vsync - 6)){
        gsSensorFunction->MMPF_Sensor_SetReg(0x350C, 0);
        gsSensorFunction->MMPF_Sensor_SetReg(0x350D, 0);

        gsSensorFunction->MMPF_Sensor_SetReg(0x3500, (ISP_UINT8)((new_shutter >> 12)&0xff));
        gsSensorFunction->MMPF_Sensor_SetReg(0x3501, (ISP_UINT8)((new_shutter >> 4)&0xff));
	    gsSensorFunction->MMPF_Sensor_SetReg(0x3502, (ISP_UINT8)((new_shutter << 4)&0xff));
    }
    else{
        ExtraVsyncWidth = (new_shutter + 6) - new_vsync;
        gsSensorFunction->MMPF_Sensor_SetReg(0x350C, (ISP_UINT8)((ExtraVsyncWidth >> 8) & 0xff));
        gsSensorFunction->MMPF_Sensor_SetReg(0x350D, (ISP_UINT8)((ExtraVsyncWidth) & 0xff));

        gsSensorFunction->MMPF_Sensor_SetReg(0x3500, (ISP_UINT8)((new_shutter >> 12)&0xff));
        gsSensorFunction->MMPF_Sensor_SetReg(0x3501, (ISP_UINT8)((new_shutter >> 4)&0xff));
        gsSensorFunction->MMPF_Sensor_SetReg(0x3502, (ISP_UINT8)((new_shutter << 4)&0xff));
    }
    return;
}

MMPF_SENSOR_FUNCTION  SensorFunction_HM1375 =
{
	MMPF_Sensor_Initialize_HM1375,
	MMPF_Sensor_InitializeVIF_HM1375,
	MMPF_Sensor_InitializeISP_HM1375,
	MMPF_Sensor_PowerDown_HM1375,
	MMPF_Sensor_SetFrameRate_HM1375,
	MMPF_Sensor_ChangeMode_HM1375,
	MMPF_Sensor_ChangePreviewMode_HM1375,
	MMPF_Sensor_SetPreviewMode_HM1375,
	MMPF_Sensor_SetReg_HM1375,
	MMPF_Sensor_GetReg_HM1375,
	MMPF_Sensor_DoAWBOperation_HM1375,
	MMPF_Sensor_DoAEOperation_ST_HM1375,
	MMPF_Sensor_DoAEOperation_END_HM1375,
	MMPF_Sensor_DoAFOperation_HM1375,
	MMPF_Sensor_DoAFOperation_FrameStart_HM1375,
	MMPF_Sensor_DoIQOperation_HM1375,
	MMPF_Sensor_SetImageEffect_HM1375,
	MMPF_SetLightFreq_HM1375,
	MMPF_SetStableState_HM1375,
	MMPF_SetHistEQState_HM1375,
	MMPF_Sensor_SetAFPosition_HM1375,
	SetAFWin_HM1375,
	SetAFEnable_HM1375,
	MMPF_Sensor_SetAEEnable_HM1375,
	MMPF_Sensor_SetAWBEnable_HM1375,
	MMPF_Sensor_SetExposureValue_HM1375,
	SetAEsmooth_HM1375,
	MMPF_Sensor_SetImageScene_HM1375,
	GetAFPosition_HM1375,
	GetAFEnable_HM1375,
	GetExposureValue_HM1375,
	GetAEsmooth_HM1375,
	MMPF_Sensor_SetAWBType_HM1375,
	MMPF_Sensor_SetContrast_HM1375,
	MMPF_Sensor_SetSaturation_HM1375,
	MMPF_Sensor_SetSharpness_HM1375,
	MMPF_Sensor_SetHue_HM1375,
	MMPF_Sensor_SetGamma_HM1375,
 //   MMPF_Sensor_SetBacklight_HM1375,
	MMPF_Sensor_SetAEMode_HM1375,
	MMPF_Sensor_SetAFMode_HM1375,
	MMPF_Sensor_SetCaptureISPSetting_HM1375,
	MMPF_Sensor_SetISPWindow_HM1375,
	MMPF_Sensor_CheckPreviewAbility_HM1375,
	MMPF_Sensor_Set3AStatus_HM1375,
	MMPF_Sensor_SetColorID_HM1375,
	MMPF_Sensor_SetSensorGain_HM1375,
	MMPF_Sensor_SetSensorShutter_HM1375
};
/*
MMPF_SENSOR_FUNCTION  SensorFunction_dummy =
{
0,0
};
*/
MMP_USHORT SNR_HM1375_Reg_Init_Customer[] = {

        //FPGA INTIALIZATION
        0x8A04, 0x01,
        0x8A00, 0x22,
        0x8A01, 0x00,
        0x8A02, 0x01,
        0x0035, 0x91,
        0x0036, 0x00,
        0x0011, 0x04,
        0x0012, 0x00,
        0x0014, 0x02,
        0x0015, 0x80,
        0x0100, 0x04,

        //SENSOR INITIALIZATION
        0x0022, 0x80,   //SFTSRT    _Soft Reset
        0x000C, 0x04,   //MODE      _Reserved bit

        0x0006, 0x00,//0x00,//0x0A,   //[1:0] Horizontal and Vertical Mirror Readout Modes
        0x000A, 0x00,   //CHIPCFG   _Full frame, chip default 00
        0x000F, 0x18,   //IMGCFG    _Select fixed frame rate
        0x0012, 0x01,   //RESERVED
        0x0013, 0x02,   //ESERVED

        0x0015, 0x01,   //INTG_H    _Set up integration
        0x0016, 0x00,   //INTG_L    _Set up integration
        0x0018, 0x00,   //AGAIN     _Set up coarse gain
        0x001D, 0x40,   //DGGAIN    _Set up fine gain

        0x0020, 0x10,   //OPRTCFG   _AE Gain enabled, Pclk transition on falling edge
        0x0023, 0x43,   //IOCNTR    _IO pad drive strength
        0x0024, 0x20,   //KCNTR     _Reserved bit
//        0x0025, 0x00,   //CKCFG     _Select PLL clock -> 24MHz to 78 MHz
        0x0026, 0x4C,//0x4C,//0x6C,
        0x0025, 0x00,   //CKCFG     _Select PLL clock -> 24MHz to 78 MHz

        //WINDOW_SCALER
        0x05E4, 0x04,//(0&0xFF),//0x04,
        0x05E5, (0x04>>8  ),//0x00,
        0x05E6, (( 0 + 1296 - 1)&0xFF),//0x0F,
        0x05E7, (( 0 + 1296 - 1)>>8  ),//0x05,

        0x05E8, 100,//(0&0xFF),//0x04,
        0x05E9, (100>>8  ),//0x00,
        0x05EA, (( 100 + 800 - 1)&0xFF),//0xDF,
        0x05EB, (( 100 + 800 - 1)>>8  ),//0x02,


        0x0027, 0x21,   //OPORTCNTR _Raw output, ITU601 Disable
        0x0028, 0x01,   //CKMUL     _Reserved bit

        0x0030, 0x00,   //EDRCFG    _Disable EDR mode
        0x0034, 0x0E,   //EDRBLEND  _Set EDR blend to 0.875
        0x0035, 0x01,   //RESERVED
        0x0036, 0x00,   //RESERVED
        0x0038, 0x02,   //EDR2AGAIN _Set up EDR2 coarse gain
        0x0039, 0x01,   //RESERVED
        0x003A, 0x01,   //RESERVED
        0x003B, 0xFF,   //ESERVED
        0x003C, 0xFF,   //RESERVED
        0x003D, 0x40,   //EDR2DGAIN _Set up EDR2 fine gain
        0x003F, 0x14,   //RESERVED  less gradient effect

        //BLACK LEVEL CONTROL
        0x0040, 0x10,   //BLCTGT    _Black level target
        0x0044, 0x07,   //BLCCFG    _BLC configuration enable, reserved bit

        //RESERVED REGISTERS FOR SENSOR READOUT_TIMING
        0x0045, 0x31,   //RESERVED
        0x0048, 0x7F,   //RESERVED
        0x004E, 0xFF,   //RESERVED
        0x0070, 0x22,   //RESERVED  - 1024 updated by Willie 4 S-2
        0x0071, 0x3F,   //RESERVED  - 1024 updated by Willie 4 S-2
        0x0072, 0x22,   //RESERVED  - 1024 updated by Willie 4 S-2
        0x0073, 0x30,   //RESERVED  - 0920 updated by Willie
        0x0074, 0x13,   //RESERVED
        0x0075, 0x40,   //RESERVED
        0x0076, 0x24,   //RESERVED
        0x0078, 0x0F,   //RESERVED
        0x007A, 0x06,   //RESERVED
        0x007B, 0x10,   //RESERVED
        0x007C, 0x10,   //RESERVED
        0x0080, 0xC9,   //RESERVED
        0x0081, 0x00,   //RESERVED
        0x0082, 0x20,   //RESERVED
        0x0083, 0xB0,   //RESERVED
        0x0084, 0x40,   //RESERVED
        0x0086, 0x3E,   //RESERVED  - 1024 updated by Willie 4 S-2
        0x0087, 0x70,   //RESERVED  - 1024 updated by Willie 4 S-2
        0x0088, 0x11,   //RESERVED
        0x0089, 0x3C,   //RESERVED  - 1024 updated by Willie 4 S-2
        0x008A, 0x87,   //RESERVED  // Rev.E updated by Willie
        0x008D, 0x64,   //RESERVED

        0x0090, 0x07,   //- 12152011 updated by Willie
        0x0091, 0x09,   //- 12152011 updated by Willie
        0x0092, 0x0C,
        0x0093, 0x0C,
        0x0094, 0x0C,
        0x0095, 0x0C,
        0x0096, 0x01,   //AGAIN gain (nonEDR) table update for CFPN improvement 0824
        0x0097, 0x00,
        0x0098, 0x04,
        0x0099, 0x08,
        0x009A, 0x0C,

        //IMAGE PIPELINE PROCESSING CONTROL
        0x0120, 0x37,   //PPCNTR1
        0x0121, 0x81,   //IPPCNTR2
        0x0122, 0xEB,   //IPPCNTR3
        0x0123, 0x29,   //IPPCNTR4
        0x0124, 0x50,   //CCMCNTR
        0x0125, 0xDE,   //IPPCNTR5
        0x0126, 0xB1,   //IPPCNTR6

        //FLARE CORRECTION
        0x013D, 0x0F,
        0x013E, 0x0F,
        0x013F, 0x0F,

        //BAD PIXEL CONTROL
        0x0140, 0x14,
        0x0141, 0x0A,
        0x0142, 0x14,
        0x0143, 0x0A,

        //RESERVED
        0x0144, 0x08,   //RESERVED
        0x0145, 0x04,   //RESERVED
        0x0146, 0x28,   //RESERVED
        0x0147, 0x3C,   //RESERVED
        0x0148, 0x28,   //RESERVED
        0x0149, 0x3C,   //RESERVED
        0x014A, 0x96,   //RESERVED
        0x014B, 0xC8,   //RESERVED

        //SHARPENING CONTROL
        0x0150, 0x14,   //SHPTHLR
        0x0151, 0x30,   //SHPTHLR_A
        0x0152, 0x54,   //SHPTHHR
        0x0153, 0x70,   //SHPTHHR_A
        0x0154, 0x14,   //SHPTHLG
        0x0155, 0x30,   //SHPTHLG_A
        0x0156, 0x54,   //SHPTHHG
        0x0157, 0x70,   //SHPTHHG_A
        0x0158, 0x14,   //SHPTHLB
        0x0159, 0x30,   //SHPTHLB_A
        0x015A, 0x54,   //SHPTHHB
        0x015B, 0x70,   //SHPTHHB_A
        0x015C, 0x30,   //SHPSTR    _Sharpness strength
        0x015D, 0x00,   //SHPSTR_A  _sharpness strength_Alpha0

        //NOISE FILTER CONTROL
        0x01D8, 0x20,   //NFHTHG
        0x01D9, 0x08,   //NFLTHG
        0x01DA, 0x20,   //NFHTHB
        0x01DB, 0x08,   //NFLTHB
        0x01DC, 0x20,   //NFHTHR
        0x01DD, 0x08,   //NFLTHR
        0x01DE, 0x50,   //NFHTHG_A
        0x01E0, 0x50,   //NFHTHB_A
        0x01E2, 0x50,   //NFHTHR_A
        0x01E4, 0x10,   //NFSTR
        0x01E5, 0x10,   //NFSTR_A
        0x01E6, 0x02,   //NFSTR_OUTA
        0x01E7, 0x10,   //NFMTHG
        0x01E8, 0x10,   //NFMTHB
        0x01E9, 0x10,   //NFMTHR
        0x01EC, 0x28,   //NFMTHR_A

        //LENS SHADING CORRECTION
        0x0220, 0x00,
        0x0221, 0xA0,
        0x0222, 0x00,
        0x0223, 0x80,
        0x0224, 0x80,
        0x0225, 0x00,
        0x0226, 0x80,
        0x0227, 0x80,
        0x0228, 0x00,
        0x0229, 0x80,
        0x022A, 0x80,
        0x022B, 0x00,
        0x022C, 0x80,
        0x022D, 0x12,
        0x022E, 0x10,
        0x022F, 0x12,
        0x0230, 0x10,
        0x0231, 0x12,
        0x0232, 0x10,
        0x0233, 0x12,
        0x0234, 0x10,
        0x0235, 0x88,
        0x0236, 0x02,
        0x0237, 0x88,
        0x0238, 0x02,
        0x0239, 0x88,
        0x023A, 0x02,
        0x023B, 0x88,
        0x023C, 0x02,
        0x023D, 0x04,
        0x023E, 0x02,
        0x023F, 0x04,
        0x0240, 0x02,
        0x0241, 0x04,
        0x0242, 0x02,
        0x0243, 0x04,
        0x0244, 0x02,
        0x0251, 0x10,

        //GAMMA CONTROL
        0x0280, 0x00,   //normal Gamma
        0x0281, 0x41,
        0x0282, 0x00,
        0x0283, 0x6D,
        0x0284, 0x00,
        0x0285, 0xBC,
        0x0286, 0x01,
        0x0287, 0x45,
        0x0288, 0x01,
        0x0289, 0x7B,
        0x028A, 0x01,
        0x028B, 0xAC,
        0x028C, 0x01,
        0x028D, 0xD2,
        0x028E, 0x01,
        0x028F, 0xF6,
        0x0290, 0x02,
        0x0291, 0x16,
        0x0292, 0x02,
        0x0293, 0x35,
        0x0294, 0x02,
        0x0295, 0x6E,
        0x0296, 0x02,
        0x0297, 0xA2,
        0x0298, 0x02,
        0x0299, 0xFF,
        0x029A, 0x03,
        0x029B, 0x51,
        0x029C, 0x03,
        0x029D, 0x9B,   //updated by MH 06/17
        0x029E, 0x00,   //slope high byte
        0x029F, 0x85,   //slope low byte
        0x02A0, 0x04,   //GAM_A

        //COLOR CORRECTION MATRIX
        0x02C0, 0x80,   //CCM00_L   _Adjust for D65 color temperature
        0x02C1, 0x01,   //CCM00_H
        0x02C2, 0x71,
        0x02C3, 0x04,
        0x02C4, 0x0F,
        0x02C5, 0x04,
        0x02C6, 0x3D,
        0x02C7, 0x04,
        0x02C8, 0x94,
        0x02C9, 0x01,
        0x02CA, 0x57,
        0x02CB, 0x04,
        0x02CC, 0x0F,
        0x02CD, 0x04,
        0x02CE, 0x8F,
        0x02CF, 0x04,
        0x02D0, 0x9E,
        0x02D1, 0x01,
        0x02E0, 0x06,   //CCM_A     _reduce to 0.267x
        0x02E1, 0xC0,   //RESERVED
        0x02E2, 0xE0,   //RESERVED
        0x02F0, 0x48,   //ACCM00_L  _Adjust for IncA color temperature
        0x02F1, 0x01,   //ACCM00_H
        0x02F2, 0x32,
        0x02F3, 0x04,
        0x02F4, 0x16,
        0x02F5, 0x04,
        0x02F6, 0x52,
        0x02F7, 0x04,
        0x02F8, 0xAA,
        0x02F9, 0x01,
        0x02FA, 0x58,
        0x02FB, 0x04,
        0x02FC, 0x56,
        0x02FD, 0x04,
        0x02FE, 0xDD,
        0x02FF, 0x04,
        0x0300, 0x33,
        0x0301, 0x02,

        //AUTOMATIC WHITE BALANCE WINDOW CONTROL
        0x0324, 0x00,
        0x0325, 0x01,

        //AUTOMATIC WHITE BALANCE DETECTION AND LIMITS
        0x0333, 0x86,
        0x0334, 0x00,
        0x0335, 0x86,

        0x0340, 0x40,
        0x0341, 0x44,
        0x0342, 0x4A,
        0x0343, 0x2B,
        0x0344, 0x94,
        0x0345, 0x3F,
        0x0346, 0x8E,
        0x0347, 0x51,
        0x0348, 0x75,
        0x0349, 0x5C,
        0x034A, 0x6A,
        0x034B, 0x68,
        0x034C, 0x5E,
        0x0350, 0x7C,
        0x0351, 0x78,
        0x0352, 0x08,
        0x0353, 0x04,
        0x0354, 0x80,
        0x0355, 0x9A,
        0x0356, 0xCC,
        0x0357, 0xFF,
        0x0358, 0xFF,
        0x035A, 0xFF,
        0x035B, 0x00,
        0x035C, 0x70,
        0x035D, 0x80,
        0x035F, 0xA0,
        0x0488, 0x30,
        0x0360, 0xDF,
        0x0361, 0x00,
        0x0362, 0xFF,
        0x0363, 0x03,
        0x0364, 0xFF,

        0x037B, 0x11,   //whole nonEDR to EDR ratio
        0x037C, 0x1E,   //EDR LONG litbin pop out to nonEDR

        //AUTOMATIC EXPOSURE CONFIGURATION
        0x0380, 0xFF,
        0x0383, 0x50,   //RESERVED
        0x038A, 0x64,
        0x038B, 0x64,
        0x038E, 0x3C,
        0x0391, 0x2A,   //RESERVED
        0x0393, 0x1E,   //RESERVED
        0x0394, 0x64,   //RESERVED
        0x0395, 0x23,
        0x0398, 0x03,   //RESERVED
        0x0399, 0x45,   //RESERVED
        0x039A, 0x06,   //RESERVED
        0x039B, 0x8B,   //RESERVED
        0x039C, 0x0D,   //RESERVED
        0x039D, 0x16,   //RESERVED
        0x039E, 0x0A,   //RESERVED
        0x039F, 0x10,
        0x03A0, 0x10,
        0x03A1, 0xE5,   //RESERVED
        0x03A2, 0x06,   //RESERVED
        0x03A4, 0x18,
        0x03A5, 0x48,
        0x03A6, 0x2D,   //RESERVED
        0x03A7, 0x78,   //RESERVED
        0x03AC, 0x5A,   //RESERVED
        0x03AD, 0x0F,   //RESERVED
        0x03AE, 0x7F,   //RESERVED
        0x03AF, 0x04,   //RESERVED
        0x03B0, 0x35,   //RESERVED
        0x03B1, 0x14,   //RESERVED

        0x036F, 0x04,   //Bayer denoise strength EDR
        0x0370, 0x0A,   //Bayer denoise strength nonEDR
        0x0371, 0x04,   //Bayer denoise strength EDR A0
        0x0372, 0x00,   //Bayer denoise strength nonEDR A0

        0x0373, 0x40,   //raw sharpness strength EDR
        0x0374, 0x20,   //raw sharpness strength nonEDR
        0x0375, 0x04,   //raw sharpness strength EDR A0
        0x0376, 0x00,   //raw sharpness strength nonEDR A0

        0x0377, 0x08,   //Y Denoise strength EDR
        0x0378, 0x08,   //Y Denoise strength nonEDR
        0x0379, 0x04,   //Y Denoise strength EDR A0
        0x037A, 0x08,   //Y Denoise strength nonEDR A0

        //DIGITAL BLACK LEVEL OFFSET CONTROL
        0x0420, 0x00,
        0x0421, 0x00,
        0x0422, 0x00,
        0x0423, 0x84,

        //AUTO BLACK LEVEL
        0x0430, 0x10,
        0x0431, 0x60,
        0x0432, 0x10,
        0x0433, 0x20,
        0x0434, 0x00,
        0x0435, 0x30,
        0x0436, 0x00,

        //LOWLIGHT_OUTDOOR IPP CONTROL
        0x0450, 0xFD,
        0x0451, 0xD8,
        0x0452, 0xA0,
        0x0453, 0x50,
        0x0459, 0x04,
        0x045A, 0x00,
        0x045B, 0x30,
        0x045C, 0x01,
        0x045D, 0x70,
        0x0460, 0x00,
        0x0461, 0x00,
        0x0462, 0x00,
        0x0465, 0x80,
        0x0466, 0x84,
        0x0478, 0x00,

        //COLOR SPACE CONVERSION_SATURATION ADJ
        0x0480, 0x60,
        0x0481, 0x06,
        0x0482, 0x0C,

        //CONTRAST_BRIGHTNESS
        0x04B0, 0x4C,   //Contrast 05032011 by mh
        0x04B1, 0x86,   //contrast 06/17 by mh
        0x04B2, 0x00,
        0x04B3, 0x18,
        0x04B4, 0x00,
        0x04B5, 0x00,
        0x04B6, 0x30,
        0x04B7, 0x00,
        0x04B8, 0x00,
        0x04B9, 0x10,
        0x04BA, 0x00,
        0x04BB, 0x00,
        0x04BD, 0x00,

        //EDR CONTRAST
        0x04D0, 0x56,
        0x04D6, 0x30,
        0x04DD, 0x10,
        0x04D9, 0x16,
        0x04D3, 0x18,

        //AE FLICKER STEP SIZE
        0x0540, 0x00,
        0x0541, 0xD1,
        0x0542, 0x00,
        0x0543, 0xFB,
        0x0580, 0x50,   //RESERVED
        0x0581, 0x30,   //RESERVED

        //Y_COLOR NOISE REDUCTION
        0x0582, 0x2D,
        0x0583, 0x16,
        0x0584, 0x1E,
        0x0585, 0x0F,
        0x0586, 0x08,
        0x0587, 0x10,
        0x0590, 0x10,
        0x0591, 0x10,
        0x0592, 0x05,
        0x0593, 0x05,
        0x0594, 0x04,
        0x0595, 0x06,

        //Y_Sharpness strength
        0x05B0, 0x04,
        0x05B1, 0x00,

        //FLEXI ENGINE_AE ADJUST CONTROL
        0x0666, 0x02,
        0x0667, 0xE0,
        0x067F, 0x19,
        0x067C, 0x00,
        0x067D, 0x00,
        0x0682, 0x00,
        0x0683, 0x00,
        0x0688, 0x00,
        0x0689, 0x00,
        0x068E, 0x00,
        0x068F, 0x00,
        0x0695, 0x00,
        0x0694, 0x00,
        0x0697, 0x19,
        0x069B, 0x00,
        0x069C, 0x20,   //max EDR ratio

        0x0720, 0x00,
        0x0725, 0x6A,
        0x0726, 0x03,
        0x072B, 0x64,
        0x072C, 0x64,
        0x072D, 0x20,
        0x072E, 0x82,   //turn off night mode
        0x072F, 0x08,

        0x0800, 0x16,
        0x0801, 0x4F,
        0x0802, 0x00,
        0x0803, 0x68,
        0x0804, 0x01,
        0x0805, 0x28,
        0x0806, 0x10,
        0x0808, 0x1D,
        0x0809, 0x18,
        0x080A, 0x10,
        0x080B, 0x07,
        0x080D, 0x0F,
        0x080E, 0x0F,
        0x0810, 0x00,
        0x0811, 0x08,
        0x0812, 0x20,
        0x0857, 0x0A,
        0x0858, 0x04,
        0x0859, 0x01,
        0x085A, 0x03,
        0x085B, 0xB0,
        0x085C, 0x04,
        0x085D, 0xBF,
        0x085E, 0x03,
        0x085F, 0xB0,
        0x0860, 0x03,
        0x0861, 0x7F,
        0x0862, 0x03,
        0x0863, 0xB0,
        0x0864, 0x02,
        0x0865, 0x7F,
        0x0866, 0x01,
        0x0867, 0x00,
        0x0868, 0x40,
        0x0869, 0x01,
        0x086A, 0x00,
        0x086B, 0x40,
        0x086C, 0x01,
        0x086D, 0x00,
        0x086E, 0x40,
        0x0870, 0x00,
        0x0871, 0x14,
        0x0872, 0x01,
        0x0873, 0x20,
        0x0874, 0x00,
        0x0875, 0x14,
        0x0876, 0x00,
        0x0877, 0xEC,

        //FLEXI ENGINE_GAMMA FOR MAXIMUM EDR
        0x0815, 0x00,
        0x0816, 0x4C,
        0x0817, 0x00,
        0x0818, 0x7B,
        0x0819, 0x00,
        0x081A, 0xCA,
        0x081B, 0x01,
        0x081C, 0x3E,
        0x081D, 0x01,
        0x081E, 0x77,
        0x081F, 0x01,
        0x0820, 0xAA,
        0x0821, 0x01,
        0x0822, 0xCE,
        0x0823, 0x01,
        0x0824, 0xEE,
        0x0825, 0x02,
        0x0826, 0x16,
        0x0827, 0x02,
        0x0828, 0x33,
        0x0829, 0x02,
        0x082A, 0x65,
        0x082B, 0x02,
        0x082C, 0x91,
        0x082D, 0x02,
        0x082E, 0xDC,
        0x082F, 0x03,
        0x0830, 0x28,
        0x0831, 0x03,
        0x0832, 0x74,
        0x0833, 0x03,
        0x0834, 0xFF,

        //FLEXI ENGINE_GAMMA FOR MINIMUM EDR
        0x0882, 0x00,
        0x0883, 0x3E,
        0x0884, 0x00,
        0x0885, 0x70,
        0x0886, 0x00,
        0x0887, 0xB8,
        0x0888, 0x01,
        0x0889, 0x28,
        0x088A, 0x01,
        0x088B, 0x5B,
        0x088C, 0x01,
        0x088D, 0x8A,
        0x088E, 0x01,
        0x088F, 0xB1,
        0x0890, 0x01,
        0x0891, 0xD9,
        0x0892, 0x01,
        0x0893, 0xEE,
        0x0894, 0x02,
        0x0895, 0x0F,
        0x0896, 0x02,
        0x0897, 0x4C,
        0x0898, 0x02,
        0x0899, 0x74,
        0x089A, 0x02,
        0x089B, 0xC3,
        0x089C, 0x03,
        0x089D, 0x0F,
        0x089E, 0x03,
        0x089F, 0x57,
        0x08A0, 0x03,
        0x08A1, 0xFF,

        //COMMAND UPDATE_TRIGGER
        0x0100, 0x01,   //CMU AE
        0x0101, 0x01,   //CMU AWB
        0x0000, 0x01,   //CMU
        0x002C, 0x00,   //Reset 8051
        0x0005, 0x01,   //Trigger


};

void SNR_HM1375_InitSensor_Customer(void) {
	// implement your initialize sensor routine here ==============================================

	ISP_UINT32 i, ret;


	//MMPF_Sensor_ConfigI2C( SENSOR_I2C_ADDR_HM1375, ISP_I2C_TYPE_2A1D);

	//ISP_HDM_IF_EnableSensor(ISP_HDM_SNR_ENABLE_HIGH);

	// set register...........
	RTNA_DBG_Str(0, "set sensor reg\r\n");
	gsSensorFunction->MMPF_Sensor_SetReg(0x0022, 0x80);
	MMPF_OS_Sleep_MS(20);
//	m_snr_I2cmAttribute.ubSlaveAddr = 0x20;
	for (i = 0; i < sizeof(SNR_HM1375_Reg_Init_Customer)/2; i++) {
//	     if (i < 11)
//	     {
//	         gsSensorFunction->MMPF_Sensor_SetReg(SNR_HM1375_Reg_Init_Customer[i*2], SNR_HM1375_Reg_Init_Customer[i*2+1]);
//	     }
//	     else if(i >= 11){
//	         m_snr_I2cmAttribute.ubSlaveAddr = 0x24;

	     gsSensorFunction->MMPF_Sensor_SetReg(SNR_HM1375_Reg_Init_Customer[i*2], SNR_HM1375_Reg_Init_Customer[i*2+1]);
	     MMPF_OS_Sleep_MS(1);
//	     if(SNR_HM1375_Reg_Init_Customer[i*2] == 0x0022 || SNR_HM1375_Reg_Init_Customer[i*2] == 0x0024)
//	     {
//	         MMPF_OS_Sleep_MS(50);
//	     }
//	     }
	}

	MMPF_OS_Sleep_MS(20);

	ISP_IF_AE_SetBaseShutter( BASE_SHUTTER_50HZ, BASE_SHUTTER_60HZ);
	ISP_IF_AE_SetMinFPSx10(75);
	// Set preview resolution as default
	SNR_HM1375_SetSensorResolution_Customer(ISP_SENSOR_RESOL_1280x720);

}

void SNR_HM1375_SetSensorAddMode_Customer(ISP_UINT8 enable)
{

}

MMP_USHORT SNR_HM1375_Reg_1280x720_Customer[] =
{
        //WINDOW_SCALER
        0x05E4, 0x04,//(0&0xFF),//0x04,
        0x05E5, (0x04>>8  ),//0x00,

        0x05E6, (( 0 + 1296 - 1)&0xFF),//0x0F,
        0x05E7, (( 0 + 1296 - 1)>>8  ),//0x05,

        0x05E8, 100,//(0&0xFF),//0x04,
        0x05E9, (100>>8  ),//0x00,
        //
        0x05EA, (( 100 + 800 - 1)&0xFF),//0xDF,
        0x05EB, (( 100 + 800 - 1)>>8  ),//0x02,

};
//extern void MMPF_Do_Mirror_Flip();
void SNR_HM1375_SetSensorResolution_Customer(ISP_SENSOR_RESOL res)
{
	// implement your change sensor resolution routine here =======================================
    MMP_ULONG i;
	MMP_ULONG VIFGrab_H_Start, VIFGrab_H_Length, VIFGrab_V_Start, VIFGrab_V_Length;

	ISP_IF_AE_SetMinFPSx10(75);
	switch (res) {
	case ISP_SENSOR_RESOL_1280x960:
	case ISP_SENSOR_RESOL_1280x720:

		// set register...........
//		for (i = 0; i < VR_ARRSIZE(SNR_HM1375_Reg_1280x720_Customer)/2; i++) {
//			gsSensorFunction->MMPF_Sensor_SetReg(SNR_HM1375_Reg_1280x720_Customer[i*2], SNR_HM1375_Reg_1280x720_Customer[i*2+1]);
//		}

		// set target fps and corresponding sensor vsync
		ISP_IF_AE_SetSensorVsync(1138, 30*10);
		//ISP_IF_AE_SetSensorVsync(0x0348, 30*10);//bossino fix m2ts AV sync @0928 ISP_IF_SNR_SetFPS(0x0348, 30);

		// set vif grab range which is fetched to ISP (for lens shading and 3A window calculation)
		VIFGrab_H_Start     = 1;//1;
		VIFGrab_H_Length    = 1280 + 8;//1288;
		VIFGrab_V_Start     = 101;//101;
		VIFGrab_V_Length    = 720 + 8;//728;

		ISP_IF_IQ_SetISPInputLength(VIFGrab_H_Length, VIFGrab_V_Length);

		// set scaler downsample rate (for scaler calculation)
		//ISP_IF_SNR_SetDownSample(1, 1);

		// set color id
#if DEFAULT_HM1375_FLIP_FOR_W8_APP
        #if SENSOR_ROTATE_180
		ISP_IF_IQ_SetColorID(1);
        #else
		ISP_IF_IQ_SetColorID(2);// mirror is 1
        #endif
#else
        #if SENSOR_ROTATE_180
		ISP_IF_IQ_SetColorID(3);
        #else
		ISP_IF_IQ_SetColorID(0);// mirror is 3
        #endif
#endif

        /*
		// set sensor grab range
		ISP_IF_IQ_SetSensorGrab(	0,					//H_Offest
									0,					//V_Offest
									VIFGrab_H_Length,	//H_Length
									VIFGrab_V_Length,	//V_Length
									1, 1, 				//H_Scale_N, H_Scale_M
									1, 1);				//V_Scale_N, V_Scale_M
		*/
		// calcuate shading ratio
		{
			ISP_UINT32 base_x, base_y;
			ISP_UINT32 x_scale_n = 0x200;
			ISP_UINT32 y_scale_n = 0x200;
			ISP_IF_IQ_GetCaliBase(&base_x, &base_y);

			x_scale_n = VIFGrab_H_Length * 0x200 / base_x;
			y_scale_n = VIFGrab_V_Length * 0x200 / base_y;

			ISP_IF_IQ_SetCaliRatio(	x_scale_n,	//x_scale_n,
									0x200,		//x_scale_m,
									0,			//x_offset,
									y_scale_n,	//y_scale_n,
									0x200,		//y_scale_m,
									0);			//y_offset
		}
		break;
	}

	// end of your implementation =================================================================

	// set VIF OPR (Actual sensor output size)
	{
		AITPS_VIF  pVIF = AITC_BASE_VIF;
		volatile MMP_BYTE* pISP = (volatile MMP_BYTE*)AITC_BASE_ISP;
		//MMP_UBYTE   vif_id = 0;

		pVIF->VIF_GRAB[vif_id].PIXL_ST = VIFGrab_H_Start;
		pVIF->VIF_GRAB[vif_id].PIXL_ED = VIFGrab_H_Start + VIFGrab_H_Length -1;
		pVIF->VIF_GRAB[vif_id].LINE_ST = VIFGrab_V_Start ;
		pVIF->VIF_GRAB[vif_id].LINE_ED = VIFGrab_V_Start + VIFGrab_V_Length -1;
		pVIF->VIF_INT_LINE_NUM_0[vif_id] = VIFGrab_V_Length - 61;//121;

#if 1
		dbg_printf(3,"ViF(xs,xe,ys,ye)=(%d,%d,%d,%d)\r\n",pVIF->VIF_GRAB[vif_id].PIXL_ST,pVIF->VIF_GRAB[vif_id].PIXL_ED,pVIF->VIF_GRAB[vif_id].LINE_ST,pVIF->VIF_GRAB[vif_id].LINE_ED);
        dbg_printf(3, "[0] VIFGrab_H_Length = %d, VIFGrab_V_Length = %d\r\n", VIFGrab_H_Length, VIFGrab_V_Length);
#endif

		if (m_gsISPCoreID == 868) {
			// ISP pipeline selection
			//APICAL_XBYTE[APICAL_CTL_REG1] &= ~(0x80); // clear auto size
			pISP[0x0B] = 0x30;
			pISP[0x09] = 0x0C;

			// IP ColorID setting
			//pISP[0x09] &= ~(0xF0);
			//pISP[0x09] |= (ISP_IF_SNR_GetColorID() == 0 ? 3 : (ISP_IF_SNR_GetColorID() == 1 ? 2 : (ISP_IF_SNR_GetColorID() == 2 ? 1: 0))) * (0x50);
		}
	}
	//================
	// set iq (NR, Edge, CCM, Gamma, etc.) and functions (saturation, contrast, sharpness, hue, etc.)
	ISP_IF_IQ_SetAll();

	// SetBeforePreview and SetBeforeCapture should be called after getting new configurations of the current resolution
	if (gSystemMode  == VENUS_SYSTEM_MODE_SNAPSHOT) {
		// update AE before capture
		ISP_IF_AE_UpdateBeforeCapture();

		// update AWB before capture
		ISP_IF_AWB_UpdateBeforeCapture();

		// special settings for capture could be set here =============================================
		{
		}
		// end of special settings ====================================================================
	} else if (gSystemMode == VENUS_SYSTEM_MODE_PREVIEW) {
		// update AE before preview
		ISP_IF_AE_UpdateBeforePreview();

		// update AWB before preview
		ISP_IF_AWB_UpdateBeforePreview();
	}

	// set direction (color ID, orientation, etc.)
	ISP_IF_IQ_SetDirection(ISP_IQ_DIRECTION_ORIGINAL);

	// set exposure parameters
	ISP_IF_IQ_SetAEGain(ISP_IF_AE_GetDGain());
	gsSensorFunction->MMPF_Sensor_SetSensorGain(ISP_IF_AE_GetAGain());
		RTNA_DBG_Str(0, "ISP_IF_AE_GetShutter ");
		RTNA_DBG_Short(0, ISP_IF_AE_GetShutter());
		RTNA_DBG_Str(0, " \n");
	gsSensorFunction->MMPF_Sensor_SetSensorShutter(ISP_IF_AE_GetShutter(), ISP_IF_AE_GetVsync());

	// update ISP window
	ISP_IF_IQ_UpdateInputSize();

	// check if modules are bypassed
	ISP_IF_IQ_CheckBypass();

	// force update iq to hardware
	ISP_IF_IQ_UpdateOprtoHW(ISP_IQ_SWITCH_ALL, 1);

}

#if (MotionDetection == 1)
static MMP_ULONG AEAcc_temp[9]={0xFFFFFFFF};
void COLOR_StoreAEAcc(void)
{
	MMP_SHORT i;
    for(i=0;i<9;i++)
    {
        AEAcc_temp[i] = AEAcc_Buffer[i];
    }
}

void COLOR_CopyAEAcc(MMP_ULONG* addr)
{
	struct _FRAME_H264_PH *header = (struct _FRAME_H264_PH *)addr;
	MMP_SHORT i;
	for(i=0;i<9;i++)
    {
    	header->dwAEAcc[i] = AEAcc_temp[i];
    }
    header->dwAELightCond = ISP_IF_AE_GetLightCond();
    header->dwAWB_GainRValue = ISP_IF_AWB_GetGainR();
    header->dwAWB_GainBValue  = ISP_IF_AWB_GetGainB();
}
#endif

#if SUPPORT_AUTO_FOCUS
void MOTOR_HM1375_VCM_InitMotor_Customer(void)
{

	//T.B.D
    dbg_printf(3, "###MOTOR_HM1375_VCM_InitMotor_Customer###\r\n");
}


void MOTOR_HM1375_VCM_EnterStandby_Customer(MMP_USHORT af_pos)
{
	//VR_Motor_SmoothMove(af_pos);

}

void MOTOR_HM1375_VCM_SetAFPosition_Customer(MMP_USHORT af_pos)
{

    //dbg_printf(3, "af_pos = %d\r\n", af_pos);
}

MMP_UBYTE MOTOR_HM1375_VCM_CheckAFreachPosition_Customer(MMP_USHORT af_pos)
{

    return 1;

}
#endif
#if (BIND_SENSOR_HM1375== 1)
MMPF_SENSOR_FUNCTION  *SensorFunction_Module0 = &SensorFunction_HM1375;
#endif

#if (BIND_SENSOR_HM1375== 2)
//MMPF_SENSOR_FUNCTION  *SensorFunction_Module0 = &SensorFunction_dummy;
MMPF_SENSOR_FUNCTION  *SensorFunction_Module1 = &SensorFunction_HM1375;
#endif

#endif  //BIND_SENSOR_HM1375
#endif
